package com.jse.dao;

import org.nutz.dao.util.cnd.SimpleCondition;
import org.nutz.dao.util.cri.SqlExpression;
import org.nutz.dao.util.cri.Static;
import org.nutz.lang.Strings;

public class Cnd extends org.nutz.dao.Cnd {

	private static final long serialVersionUID = 5473140334491239035L;
	
	protected Cnd(SqlExpression exp) {
		super(exp);
	}
	protected Cnd(String exp) {
		super(new Static(exp));
	}
	
	public Cnd and(SqlExpression exp) {
		getCri().where().and(exp);
		return this;
	}
	
	public Cnd and(String exp) {
		getCri().where().and(new Static(exp));
		return this;
	}
	
	
	public Cnd where(String exp) {
		return and(new Static(exp));
	}
	
	public Cnd or(String exp) {
		getCri().where().or(new Static(exp));
        return this;
	}
	public static Cnd where(String name,String op,Object value) {
		return new Cnd(Cnd.exp(name, op, value));
	}
	/***
     * 直接用字符串生成一个条件对象
     * @param str sql条件
     * @return 条件对象
     */
    public static Cnd wrap(String str) {
        return new Cnd(Strings.isBlank(str) ? null : new SimpleCondition((Object) str).toString());
    }
    
    public static Cnd NEW() {
        return new Cnd("1 = 1");
    }
}
